<template>
  <div class="collection">
    <div class="title">
      <i class="iconfont icon-xiangzuo" @click="$router.go(-1), change()"></i>
      <div class="story">收藏</div>
    </div>

    <div class="collectionCon">
      <ul>
        <li :class="{ con: flag == 0 }" @click="flag = 0">书籍</li>
        <li :class="{ con: flag == 1 }" @click="flag = 1">书单</li>
      </ul>
    </div>

    <div class="mineContent">
      <ul>
        <li v-show="flag == 0">
          <div class="icon" v-if="!mes">
            <i class="iconfont icon-shu"></i>
            <p>暂时没有书籍</p>
          </div>
          <div class="mineBooks" v-show="mes">
            <div
              class="item"
              v-for="item in mes"
              :key="item.id"
              @click="$router.push({ name: 'synopsis', query: { id: item.id } })"
            >
              <div class="img">
                <img :src="item.img" />
              </div>
              <p>{{ item.title }}</p>
            </div>
          </div>
        </li>
        <li v-show="flag == 1">
          <div class="icon">
            <i class="iconfont icon-shu"></i>
            <p>暂时没有书单</p>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      flag: 0,
      mes: null,
    };
  },
  methods: {
    change() {
      this.$emit("getnavs-btn", true);
    },
  },
  created() {
    this.$emit("getnavs-btn", false);
    this.mes = JSON.parse(localStorage.getItem("collection"));
    console.log(this.mes);
  },
};
</script>

<style lang="less">
.collection {
  .title {
    position: fixed;
    width: 100%;
    min-height: 50px;
    display: flex;
    background-color: #fff;
    z-index: 1;
    i {
      flex: 0 0 40px;
      text-align: center;
      line-height: 50px;
      font-size: 20px;
    }
    .story {
      flex: 1;
      text-align: center;
      line-height: 50px;
      font-size: 18px;
      padding-right: 40px;
    }
  }
  .collectionCon {
    padding-top: 50px;
    ul {
      display: flex;
      justify-content: space-between;
      background-color: #fff;
      li {
        width: 50%;
        text-align: center;
        padding: 10px 0;
        border-bottom: 1px solid #f6f7f9;
      }
    }
    .con {
      color: rgb(35, 179, 130);
      border-color: rgb(35, 179, 130);
    }
  }
  .mineContent {
    width: 100%;
    height: 100%;
    background-color: #fff;
    ul {
      padding: 15px;
      li {
        .mineBooks {
          display: flex;
          flex-wrap: wrap;
          .item {
            margin-bottom: 10px;
            margin-right: 10.5px;
            margin-left: 10.5px;
            .img {
              img {
                width: 70px;
                height: 90px;
              }
            }
            p {
              font-size: 12px;
              padding: 4px 0;
              width: 70px;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
            }
          }
          :first-child,
          :nth-child(4n + 1) {
            margin-left: 0;
          }
          :nth-child(4n) {
            margin-right: 0;
          }
        }
        .icon {
          margin: 180px auto;
          text-align: center;
          i {
            font-size: 100px;
            color: rgb(35, 179, 130);
          }
          p {
            font-size: 14px;
            margin-top: 15px;
          }
        }
      }
    }
  }
}
</style>